package com.sali.b_design_pattern.g_singleton_pattern.lesson_singleton.b_lazy.a_synchron;

// 在懒汉模式的基础上，可以使⽤双重检查锁来提⾼性能
public class SingletonV2 {

    private static volatile SingletonV2 instance;

    private SingletonV2() {
        // 私有构造⽅法，防⽌外部实例化
    }

    public static SingletonV2 getInstance() {
        if (instance == null) {
            synchronized (SingletonV2.class) {
                if (instance == null) {
                    instance = new SingletonV2();
                }
            }
        }
        return instance;
    }

}
